<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="common::head"></head>
<body>
<div th:replace="common::top"></div>
<br/>
<h2>新增用户</h2>
<form th:action="@{add}" method="post" id="addForm">
    <label>用户:</label>
    <input type="text" name="userName">
    <br/>
    <label>密码:</label>
    <input type="password" name="password">
    <br/>
    <label>角色:</label>
    <input type="checkbox" name="roles" value="SALE"><label>销售</label>
    <input type="checkbox" name="roles" value="WORKER"><label>生产</label>
    <input type="checkbox" name="roles" value="FINANCE"><label>财务</label>
    <br/>
    <input type="submit" value="注册">
</form>
<script>
    $("#addForm").submit(function(e){
        e.preventDefault();

        $.ajax({
            type: $("#addForm").attr("method"),
            url: $("#addForm").attr("action"),
            data: $("#addForm").serialize(),
            success: function(response){
                alert("提交成功");
                window.location.href="list.html";
            },
            error: function(response){
                alert("提交失败");
            }
        });
    });
</script>
</body>
</html>